package com.fwj.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fwj.gmall.model.product.BaseTrademark;
import com.fwj.gmall.model.product.SpuImage;
import com.fwj.gmall.model.product.SpuInfo;
import com.fwj.gmall.model.product.SpuSaleAttr;
import com.fwj.gmall.product.service.SpuService;
import com.fwj.gmall.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/admin/product/")
@RestController
@Api("获取spu分页列表")
public class SpuController {

    @Autowired
    SpuService spuService;


    @ApiOperation("获取spu分页列表")
    @GetMapping("{page}/{limit}")
    public Result spuList(@PathVariable("page") Long page, @PathVariable("limit") Long limit, Long category3Id) {

        IPage<SpuInfo> infoIPage = spuService.spuList(page, limit, category3Id);

        return Result.ok(infoIPage);
    }

    @ApiOperation("获取销售属性")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList() {

        List<SpuSaleAttr> spuSaleAttrList = spuService.baseSaleAttrList();

        return Result.ok(spuSaleAttrList);

    }

    @ApiOperation("获取品牌属性")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList() {

        List<BaseTrademark> baseTrademarkList = spuService.getTrademarkList();

        return Result.ok(baseTrademarkList);
    }

    @ApiOperation("添加spu")
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {

        spuService.saveSpuInfo(spuInfo);

        return Result.ok();
    }

    @ApiOperation("根据spuId获取图片列表")
    @GetMapping("spuImageList/{spuId}")
    public Result spuImageList(@PathVariable("spuId") Long spuId) {

        List<SpuImage> skuImageList = spuService.spuImageList(spuId);

        return Result.ok(skuImageList);
    }

    @ApiOperation("根据skuId获取销售属性")
    @GetMapping("spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable("spuId") Long spuId) {

        List<SpuSaleAttr> spuSaleAttrList = spuService.spuSaleAttrList(spuId);


        return Result.ok(spuSaleAttrList);
    }


}
